package com.dudu.service.impl;

import com.dudu.dao.LearnResourceMapper;
import com.dudu.dao.LearnUserMapper;
import com.dudu.domain.LearnResource;
import com.dudu.domain.LearnUser;
import com.dudu.service.LearnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by tengj on 2017/4/7.
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class LearnServiceImpl extends BaseService<LearnResource>  implements LearnService {

    @Autowired
    private LearnResourceMapper  learnResourceMapper;

    @Autowired
    private LearnUserMapper learnUserMapper;

    @Override
    public void testTransactional() {
        LearnResource learnResource = new LearnResource();
        learnResource.setAuthor("测试作者");
        learnResource.setTitle("测试标题");
        learnResource.setUrl("http://www.x.com");
        learnResourceMapper.insertSelective(learnResource);

        LearnUser learnUser =new LearnUser();
        learnUser.setResId(learnResource.getId());
        learnUser.setName("测试姓名");

        //数据库设置必填项，但是不设置写入
//        learnUser.setPhone("18000000001");
        learnUserMapper.insertSelective(learnUser);
    }
}
